package com.yaoyong.codegenerator.config;

import com.yaoyong.codegenerator.properties.DatabaseProperties;
import com.yaoyong.codegenerator.utils.DatabaseUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 姚勇
 */
@Configuration
@EnableConfigurationProperties(value = {DatabaseProperties.class})
@ConditionalOnClass(value = {DatabaseUtil.class})
@ConditionalOnProperty(prefix = "code.generator.database", value = "enabled", matchIfMissing = true)
public class DataBaseUtilAutoConfig {

    @Bean
    @ConditionalOnMissingBean(value = {DatabaseUtil.class})
    public DatabaseUtil databaseUtil() {
        return new DatabaseUtil();
    }

}
